package com.klun.concDesign.chaptersix;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

public class PrimeUtil {
    public static boolean isPrime(int number){
        int tmp = number;
        if(tmp < 2){
            return false;
        }
        for (int i = 2; Math.sqrt(tmp) >= i; i++) {
            if(tmp % i == 0){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        // 串行统计
        IntStream.range(1,100000).filter(PrimeUtil::isPrime).count();
        // 串行统计
        IntStream.range(1,100000).parallel().filter(PrimeUtil::isPrime).count();

        List<Student> students = new ArrayList<>();
        double ave0 = students.stream().mapToInt(s -> s.getScore()).average().getAsDouble();

        double ave1 = students.parallelStream().mapToInt(s -> s.getScore()).average().getAsDouble();

        int[] arr = new int[10000000];
        Arrays.parallelSort(arr);
    }
}
class Student{
    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
}